package com.web44.mapper;

import com.web44.bean.User;
import org.apache.ibatis.annotations.*;

import java.util.List;
import java.util.Map;

/**
 * @Title: UserMapper
 * @Description:
 * @Auther: py
 * @Version: 1.0
 * @create 2024/1/3 9:06
 */
public interface UserMapper {


    @Select("select * from `t_user`")
    List<User> queryUsers();
    /**
     * 新增没有返回自增主键
     *
     * @param user
     */
    @Insert("insert into t_user(user_name,password,age,gender) values(#{userName},#{password},#{age},#{gender})")
    void addUser(User user);

    @Insert("insert into t_user(user_name,password,age,gender) values(#{userName},#{password},#{age},#{gender})")
    @Options(useGeneratedKeys = true, keyProperty = "id", keyColumn = "id")
    int insertUser(User user);

    @Update("update t_user set user_name=#{userName},age=#{age} where id=#{id}")
    void editUser(User user);

    @Delete("delete from t_user where id=#{id}")
    void delUser(@Param("id") int id);

    @Select("select * from t_user where id=#{id}")
    User queryUserById(@Param("id") int id);

    // @Select("select * from t_user where user_name like concat('%',#{userName},'%')")
    @Select("select * from t_user where user_name like '%${userName}%'")
    List<User> queryUsersByUserName(@Param("userName") String userName);

    @Select("select count(id) from t_user")
    int queryUserCount();
}